package com.peng.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.peng.common.R;
import com.peng.entity.Category;
import com.peng.entity.Employee;
import com.peng.service.CategoryService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


@RestController
@RequestMapping("/category")
public class CategoryController {
    @Resource
    private CategoryService categoryService;

    @GetMapping("/page")
    public R<IPage<Category>> pageR(Integer page, Integer pageSize, String name){
        IPage page1= categoryService.pageR(page,pageSize,name);
        return R.success(page1);
    }

    @GetMapping("/list")
    public R<List<Category>> listR( Category category){
        List<Category> categories= categoryService.listR(category);
        return R.success(categories);
    }

    @PostMapping
    public R saveCategory(@RequestBody Category category){
        categoryService.saveOrUpdate(category);
        return R.success("添加成功");
    }

    @PutMapping
    public R updateCategory(@RequestBody Category category){
        categoryService.saveOrUpdate(category);
        return R.success("修改成功");
    }

    @DeleteMapping
    public R deleteCategory(Long ids){
        categoryService.remove(ids);
        return R.success("删除成功");
    }
}

